##          used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
## Ncells 532590 28.5    1186980 63.4         NA   669411 35.8
## Vcells 989513  7.6    8388608 64.0     131072  1851571 14.2

1 setting up environments

1.1 Note

Here we the ABCD release 4.0 data-set

1.2 Loading libraries

The following libraries and default settings were used during the analysis:

Changes: psychopathology to mental health

options(scipen = 999)
#library("sva")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library("tidymodels")
## ── Attaching packages ────────────────────────────────────── tidymodels 1.1.0 ──
## ✔ broom        1.0.5     ✔ rsample      1.1.1
## ✔ dials        1.2.0     ✔ tune         1.1.1
## ✔ infer        1.0.4     ✔ workflows    1.1.3
## ✔ modeldata    1.2.0     ✔ workflowsets 1.0.1
## ✔ parsnip      1.1.0     ✔ yardstick    1.2.0
## ✔ recipes      1.0.7     
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## ✖ scales::discard() masks purrr::discard()
## ✖ dplyr::filter()   masks stats::filter()
## ✖ recipes::fixed()  masks stringr::fixed()
## ✖ dplyr::lag()      masks stats::lag()
## ✖ yardstick::spec() masks readr::spec()
## ✖ recipes::step()   masks stats::step()
## • Use suppressPackageStartupMessages() to eliminate package startup messages
##parallel map
library(partR2)
## 
## Attaching package: 'partR2'
## 
## The following object is masked from 'package:modeldata':
## 
##     biomass
library(lme4)
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## 
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
library(yhat)
library(ggtext)
library(ggpubr)
library(cowplot)
## 
## Attaching package: 'cowplot'
## 
## The following object is masked from 'package:ggpubr':
## 
##     get_legend
## 
## The following object is masked from 'package:lubridate':
## 
##     stamp
library(partR2)
library(lme4)
library(yhat)
library("VennDiagram")
## Loading required package: grid
## Loading required package: futile.logger
## 
## Attaching package: 'VennDiagram'
## 
## The following object is masked from 'package:ggpubr':
## 
##     rotate
library(viridis)
## Loading required package: viridisLite
## 
## Attaching package: 'viridis'
## 
## The following object is masked from 'package:scales':
## 
##     viridis_pal
library(ggpointdensity)
library(ggthemes)
## 
## Attaching package: 'ggthemes'
## 
## The following object is masked from 'package:cowplot':
## 
##     theme_map
theme_set(theme_bw() + theme(panel.grid = element_blank()))
## parallel processing number of cores register
all_cores <- parallel::detectCores(logical = FALSE) - 5

doParallel::registerDoParallel(cores = all_cores)

1.3 Setting up path

We first loaded all of the relevant data files (not shown here as they refer to local directories):

2 Data Preparation

2.1 load fitted gfactors from brain scan and psychopathology

2.1.1 load brain scan fitted results from stacking models

rf_baseline <- readRDS(paste0(scriptfold,"stacking_gfactor_modelling/collect_random_forest_results/random_forest_baseline_results.RDS"))

rf_followup <- readRDS(paste0(scriptfold,"stacking_gfactor_modelling/collect_random_forest_results/random_forest_followup_results.RDS"))

2.1.2 load the psychopathology predicted results

psy_pred <- readRDS(paste0(scriptfold,"Common_psy_gene_brain_all/saved_outputs/psychopathology_pls_pred_2.0.RData"))

2.1.3 load the computed gfactor

gfactor_list <- readRDS(paste0(scriptfold,"genetics_psychopathology_common_scan_all_scripts/gfactor_scale_seperate.RData"))

2.1.4 genetics predictions

load in genetics related to cognition predicted results

genetics_cog <- readRDS(paste0(scriptfold,'genetics_psychopathology_common_scan_all_scripts/psychopathology_cog_gene_pred_residual', '.RData'))

2.1.5 Soc-Dem-Life-Dev predictions

gfactor_ses <- readRDS(paste0(scriptfold,'genetics_psychopathology_common_scan_all_scripts/ses_pls_pred', '.RData'))

2.2 process loaded data

Be careful with what site you choose.

Extract the needed data sets from the list.

rf_baseline_pred <- map(rf_baseline,"test_pred")
rf_baseline_pred_tibble <- map(rf_baseline_pred,"model_predict")
rf_baseline_table <- map(rf_baseline,"test_data")

rf_followup_pred <- map(rf_followup,"test_pred")
rf_followup_pred_tibble <- map(rf_followup_pred,"model_predict")
rf_followup_table <- map(rf_followup,"test_data")
gfactor_baselie_test <- map(gfactor_list,"output_test_baseline")
gfactor_followup_test <- map(gfactor_list,"output_test_followup")
subj_info <- c("SUBJECTKEY","SITE_ID_L","EVENTNAME")

2.2.1 process data of brain and mental health

## this function extract the subject information and join those information to the predicted results
pred_processing <- function(baseline_pred, followup_pred, baseline_table, followup_table,pred_name){
  names_vec <- c(subj_info,pred_name)
  
  baseline_subj_info <- baseline_table %>% select(all_of(subj_info))
  baseline_pred_vec <- baseline_pred %>% select(model_predict)
  baseline_output <- bind_cols(baseline_subj_info,baseline_pred_vec)
  names(baseline_output) <- names_vec
  
  followup_subj_info <- followup_table %>% select(all_of(subj_info))
  followup_pred_vec <- followup_pred %>% select(model_predict)
  followup_output <- bind_cols(followup_subj_info,followup_pred_vec)
  names(followup_output) <- names_vec

  output_all <- bind_rows(baseline_output,followup_output)
  return(list(baseline_output = baseline_output,
              followup_output = followup_output))
}
processed_rf_results <- pmap(list(rf_baseline_pred_tibble,rf_baseline_table,
                                  rf_followup_pred_tibble,rf_followup_table),
                             ~pred_processing(baseline_pred=..1,
                                              followup_pred=..3, 
                                              baseline_table=..2, 
                                              followup_table=..4,
                                              pred_name="random_forest_stacking"))


processed_psy_results <- pmap(list(psy_pred[["baseline_test_pred"]],
                                   psy_pred[["baseline_test_data"]],
                                  psy_pred[["followup_test_pred"]],
                                  psy_pred[["followup_test_data"]]),
                             ~pred_processing(baseline_pred=..1,
                                              followup_pred=..3, 
                                              baseline_table=..2, 
                                              followup_table=..4,
                                              pred_name="psychopathology"))
site_char <- names(processed_psy_results)

2.2.2 process data of genes

genetics_cog_baseline_pred <-genetics_cog[["baseline_test_pred"]]
genetics_cog_baseline_table <-genetics_cog[["baseline_test_data"]]

genetics_cog_followup_pred <- genetics_cog[["followup_test_pred"]]
genetics_cog_followup_data <- genetics_cog[["followup_test_data"]]


pred_processing_gene <- function(baseline_pred, followup_pred, baseline_table, followup_table,pred_name){
  names_vec <- c(c("SUBJECTKEY","SITE_ID_L"),pred_name)
  
  baseline_subj_info <- baseline_table %>% select(all_of(c("SUBJECTKEY","SITE_ID_L")))
  baseline_pred_vec <- baseline_pred %>% select(model_predict)
  baseline_output <- bind_cols(baseline_subj_info,baseline_pred_vec)
  names(baseline_output) <- names_vec
  
  followup_subj_info <- followup_table %>% select(all_of(c("SUBJECTKEY","SITE_ID_L")))
  followup_pred_vec <- followup_pred %>% select(model_predict)
  followup_output <- bind_cols(followup_subj_info,followup_pred_vec)
  names(followup_output) <- names_vec

  output_all <- bind_rows(baseline_output,followup_output)
  return(list(baseline_output = baseline_output,
              followup_output = followup_output))
}

processed_gene_results <- pmap(list(genetics_cog_baseline_pred,genetics_cog_baseline_table,
                                  genetics_cog_followup_pred,genetics_cog_followup_data),
                             ~pred_processing_gene(baseline_pred=..1,
                                              followup_pred=..3, 
                                              baseline_table=..2, 
                                              followup_table=..4,
                                              pred_name="gene_cog"))

2.2.3 process the data of Soc-Dem-Life-Dev

gfactor_ses_baseline_pred <-gfactor_ses[["baseline_test_pred"]]
gfactor_ses_baseline_table <-gfactor_ses[["baseline_test_data"]]

gfactor_ses_followup_pred <- gfactor_ses[["followup_test_pred"]]
gfactor_ses_followup_data <- gfactor_ses[["followup_test_data"]]


processed_ses_results <- pmap(list(gfactor_ses_baseline_pred,gfactor_ses_baseline_table,
                                  gfactor_ses_followup_pred,gfactor_ses_followup_data),
                             ~pred_processing_gene(baseline_pred=..1,
                                              followup_pred=..3, 
                                              baseline_table=..2, 
                                              followup_table=..4,
                                              pred_name="ses"))

2.3 join the individual data sets with gfactor

join_pred_gfactor <- function(data_input, site_input){
  data_baseline_tibble <- data_input[[site_input]][["baseline_output"]]
  data_followup_tibble <- data_input[[site_input]][["followup_output"]]
  
  gfactor_baseline <- gfactor_baselie_test[[site_input]]
  gfactor_followup <- gfactor_followup_test[[site_input]]

  output_baseline <- plyr::join_all(list(data_baseline_tibble,gfactor_baseline),by="SUBJECTKEY",type = "full")%>%
    drop_na()
  output_followup <- plyr::join_all(list(data_followup_tibble,gfactor_followup),by="SUBJECTKEY",type="full")%>%
    drop_na()
 output_all <- bind_rows(output_baseline,output_followup)
  
  return(list(baseline = output_baseline,
              followup=output_followup,
              all = output_all))
}

Features: stacking brain models, mental health, genes and Soc-Dem-Life-Dev are joined with response variable individually,

gfactor_rf <- map(.x = site_char,~join_pred_gfactor(data_input =processed_rf_results, site_input = .x))

names(gfactor_rf) <- site_char

gfactor_rf_baseline <- map(gfactor_rf,"baseline")%>% do.call(rbind,.)
gfactor_rf_followup <- map(gfactor_rf,"followup")%>% do.call(rbind,.)
gfactor_rf_baseline_followup <- map(gfactor_rf,"all")%>% do.call(rbind,.)



gfactor_psy <- map(.x = site_char,~join_pred_gfactor(data_input =processed_psy_results, site_input = .x))

names(gfactor_psy) <- site_char

gfactor_psy_baseline <- map(gfactor_psy,"baseline")%>% do.call(rbind,.)
gfactor_psy_followup <- map(gfactor_psy,"followup")%>% do.call(rbind,.)
gfactor_psy_baseline_followup <- map(gfactor_psy,"all")%>% do.call(rbind,.)


gfactor_gene <- map(.x = site_char,~join_pred_gfactor(data_input =processed_gene_results, site_input = .x))

names(gfactor_gene) <- site_char

gfactor_gene_baseline <- map(gfactor_gene,"baseline")%>% do.call(rbind,.)%>%
                        filter(gene_cog < 3)
### try to detect outliers
map(gfactor_gene,"baseline")%>% do.call(rbind,.)%>%
                        filter(gene_cog > 3)%>%
                        print()
## [1] SUBJECTKEY SITE_ID_L  gene_cog   gfactor   
## <0 rows> (or 0-length row.names)
gfactor_gene_followup <- map(gfactor_gene,"followup")%>% do.call(rbind,.)%>%
                        filter(gene_cog < 3)
gfactor_gene_baseline_followup <- map(gfactor_gene,"all")%>% do.call(rbind,.)%>%
                        filter(gene_cog < 3)


gfactor_ses <- map(.x = site_char,~join_pred_gfactor(data_input =processed_ses_results, site_input = .x))

names(gfactor_ses) <- site_char

gfactor_ses_baseline <- map(gfactor_ses,"baseline")%>% do.call(rbind,.)
gfactor_ses_followup <- map(gfactor_ses,"followup")%>% do.call(rbind,.)
gfactor_ses_baseline_followup <- map(gfactor_ses,"all")%>% do.call(rbind,.)

2.4 Combine data and creating names

pred_gfactor_baseline <- list(rf = gfactor_rf_baseline,
                              psy = gfactor_psy_baseline, 
                              gene = gfactor_gene_baseline,
                              ses =gfactor_ses_baseline)

pred_gfactor_followup <- list(rf = gfactor_rf_followup,
                              psy = gfactor_psy_followup, 
                              gene = gfactor_gene_followup,
                              ses =gfactor_ses_followup)

3 Metric tables

3.1 Reading in all the performances metrics tables

Load the data input of the performance metrics

brain_performance_metric <- readRDS(paste0(scriptfold,'Common_psy_gene_brain_all/saved_outputs/performance_metrics/brain_performance_metric', '.RData'))

gene_performance_metric <- readRDS(paste0(scriptfold,'Common_psy_gene_brain_all/saved_outputs/performance_metrics/gene_performance_metric', '.RData'))

mental_health_performance_metric <- readRDS(paste0(scriptfold,'Common_psy_gene_brain_all/saved_outputs/performance_metrics/mental_health_performance_metric', '.RData'))

ses_performance_metric <- readRDS(paste0(scriptfold,'Common_psy_gene_brain_all/saved_outputs/performance_metrics/ses_performance_metric', '.RData'))


set_of_brain_features_performance_metric <- readRDS(paste0(scriptfold,'Common_psy_gene_brain_all/saved_outputs/performance_metrics/set_of_brain_features_performance_metric', '.RData'))

3.2 Joining the tables together and shift the orders.

brain_performance_metric_baseline <- brain_performance_metric %>%
                                     filter(event == "baseline")%>%
                                     select(-event)

features_reorder_vec <- c("modality","correlation (sd)", "tradrsq (sd)", "MAE (sd)","RMSE (sd)")

new_names_vec <- c("Features","Correlation", "Traditional R-squared", "MAE","RMSE" )

brain_performance_metric_baseline<- brain_performance_metric_baseline[,features_reorder_vec]

names(brain_performance_metric_baseline) <-new_names_vec
                                

brain_performance_metric_followup<- brain_performance_metric %>%
                                     filter(event == "followup")%>%
                                     select(-event)
brain_performance_metric_followup<- brain_performance_metric_followup[,features_reorder_vec]

names(brain_performance_metric_followup) <-new_names_vec

gene_performance_metric_baseline <- gene_performance_metric%>%
                                     filter(event == "baseline")%>%
                                     select(-event)

gene_performance_metric_baseline<- gene_performance_metric_baseline[,features_reorder_vec]

names(gene_performance_metric_baseline) <-new_names_vec

gene_performance_metric_followup <-  gene_performance_metric%>%
                                     filter(event == "followup")%>%
                                     select(-event)

gene_performance_metric_followup<- gene_performance_metric_followup[,features_reorder_vec]

names(gene_performance_metric_followup) <-new_names_vec

mental_health_performance_metric_baseline <-  mental_health_performance_metric%>%
                                     filter(event == "baseline")%>%
                                     select(-event)

mental_health_performance_metric_baseline<- mental_health_performance_metric_baseline[,features_reorder_vec]

names(mental_health_performance_metric_baseline) <-new_names_vec

mental_health_performance_metric_followup <-  mental_health_performance_metric%>%
                                     filter(event == "followup")%>%
                                     select(-event)

mental_health_performance_metric_followup<- mental_health_performance_metric_followup[,features_reorder_vec]

names(mental_health_performance_metric_followup) <-new_names_vec

ses_performance_metric_baseline <- ses_performance_metric%>%
                                     filter(event == "baseline")%>%
                                     select(-event)


ses_performance_metric_baseline<- ses_performance_metric_baseline[,features_reorder_vec]

names(ses_performance_metric_baseline) <-new_names_vec

ses_performance_metric_followup <-  ses_performance_metric%>%
                                     filter(event == "followup")%>%
                                     select(-event)

ses_performance_metric_followup<- ses_performance_metric_followup[,features_reorder_vec]

names(ses_performance_metric_followup) <-new_names_vec

set_of_brain_features_performance_metric_baseline <-  set_of_brain_features_performance_metric%>%
                                     filter(event == "baseline")%>%
                                     select(-event)

set_of_brain_features_performance_metric_baseline<- set_of_brain_features_performance_metric_baseline[,features_reorder_vec]

names(set_of_brain_features_performance_metric_baseline) <-new_names_vec

set_of_brain_features_performance_metric_followup <- set_of_brain_features_performance_metric%>%
                                     filter(event == "followup")%>%
                                     select(-event)

set_of_brain_features_performance_metric_followup<- set_of_brain_features_performance_metric_followup[,features_reorder_vec]

names(set_of_brain_features_performance_metric_followup) <-new_names_vec

4 scatterplots

4.1 Loading in all the scatterplots from other files

psy_seperate_plot_baseline <- readRDS(paste0(scriptfold,'Common_psy_gene_brain_all/saved_outputs/scatter_plots/psy_seperate_plot_baseline', '.RData'))

psy_seperate_plot_followup <- readRDS(paste0(scriptfold,'Common_psy_gene_brain_all/saved_outputs/scatter_plots/psy_seperate_plot_followup', '.RData'))


scatter_legend <- readRDS(paste0(scriptfold,'Common_psy_gene_brain_all/saved_outputs/scatter_plots/scatter_legend', '.RData'))
names_vec <- c("Brain", "Mental Health", "Genes", "Social Demo Lifestyle Dev")

pred_names <- c("random_forest_stacking","psychopathology","gene_cog","ses" )
## create the labels
cor_label_vec_baseline <- c(brain_performance_metric_baseline$Correlation,
                            mental_health_performance_metric_baseline$Correlation[1],
                            gene_performance_metric_baseline$Correlation,
                            ses_performance_metric_baseline$Correlation)
cor_label_vec_followup <- c(brain_performance_metric_followup$Correlation,
                            mental_health_performance_metric_followup$Correlation[1],
                            gene_performance_metric_followup$Correlation,
                            ses_performance_metric_followup$Correlation)


scatter_plot_gfactor_new <- function(data_input,name_input,pred_names,cor_labels){
  
  scatter_plot <-  ggplot(data_input,aes(x = scale(.data[[pred_names]]) , 
                     y = scale(.data[["gfactor"]]))) +
  geom_pointdensity(size = 1) +
       scale_color_viridis()+
  geom_smooth(method = 'lm', se = FALSE, col = 'black')  +
  labs(x = NULL,
       y = NULL,
       title = paste (name_input,'\nr = ',cor_labels))+
     scale_x_continuous(limits=c(-5,5))+
     scale_y_continuous(limits=c(-5,5))+
        theme_classic() + 
             theme(axis.text.x = element_text(size = 35),                      
                           axis.text.y = element_text(size = 35),                     
                           plot.title = element_text(size=35)) +
     theme(
    strip.background = element_blank(),
    strip.text.x = element_blank(),
    legend.position = "none")
 return(scatter_plot)
  
}


scatter_plot_baseline_new <- pmap(list(pred_gfactor_baseline,names_vec,pred_names,cor_label_vec_baseline),
                              ~scatter_plot_gfactor_new(data_input = ..1,
                                                    name_input = ..2,
                                                    pred_names = ..3,
                                                    cor_labels = ..4))



scatter_plot_followup_new <- pmap(list(pred_gfactor_followup,names_vec,pred_names,cor_label_vec_followup),
                              ~scatter_plot_gfactor_new(data_input = ..1,
                                                    name_input = ..2,
                                                    pred_names = ..3,
                                                    cor_labels = ..4))


### manually change the order of the plots
scatter_baseline_mental_health <- vector("list",length = 4)

scatter_baseline_mental_health[[1]] <- scatter_plot_baseline_new[[2]]
scatter_baseline_mental_health[[2]] <- psy_seperate_plot_baseline[[2]]
scatter_baseline_mental_health[[3]] <- psy_seperate_plot_baseline[[1]]
scatter_baseline_mental_health[[4]] <- psy_seperate_plot_baseline[[3]]

scatter_baseline_all<- vector("list",length = 3)

scatter_baseline_all[[1]] <- scatter_plot_baseline_new[[1]]
scatter_baseline_all[[2]] <- scatter_plot_baseline_new[[3]]
scatter_baseline_all[[3]] <- scatter_plot_baseline_new[[4]]

scatter_followup_mental_health <- vector("list",length = 4)

scatter_followup_mental_health[[1]] <- scatter_plot_followup_new[[2]]
scatter_followup_mental_health[[2]] <- psy_seperate_plot_followup[[2]]
scatter_followup_mental_health[[3]] <- psy_seperate_plot_followup[[1]]
scatter_followup_mental_health[[4]] <- psy_seperate_plot_followup[[3]]

scatter_followup_all <- vector("list",length = 3)


scatter_followup_all[[1]] <- scatter_plot_followup_new[[1]]
scatter_followup_all[[2]] <- scatter_plot_followup_new[[3]]
scatter_followup_all[[3]] <- scatter_plot_followup_new[[4]]

4.2 Arrange the plots with all the mental health features

## plots with mental health

scatter_baseline_grid_mental_health <-ggpubr::ggarrange(plotlist = scatter_baseline_mental_health,
                                                        ncol = 4,nrow = 1) %>%
                  #                                      legend.grob = scatter_legend,
                  #                                      legend="top")%>%
                            ggpubr::annotate_figure(top = ggpubr::text_grob("Baseline",size=45,face="bold",hjust=3.4)) %>%
  ggpubr::ggarrange(                                    legend.grob = scatter_legend,
                                                        legend="top")
## Warning: Removed 2 rows containing non-finite values (`stat_pointdensity()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 9 rows containing non-finite values (`stat_pointdensity()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 9 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2 rows containing non-finite values (`stat_pointdensity()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
scatter_followup_grid_mental_health <-ggpubr::ggarrange(plotlist = scatter_followup_mental_health,
                                                        ncol = 4,nrow = 1)%>%
                            ggpubr::annotate_figure(top = ggpubr::text_grob("Followup",face="bold",size=45,hjust=3.2))
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 9 rows containing non-finite values (`stat_pointdensity()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 9 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
scatter_all_grid_mental_health <- ggpubr::ggarrange(scatter_baseline_grid_mental_health,scatter_followup_grid_mental_health,nrow = 2)

labelled_scatter_mental_health <- ggpubr::annotate_figure(scatter_all_grid_mental_health,
                          left= ggpubr::text_grob("Observed Cognitive Abilities (Z)",size=45,rot=90),
                        bottom = ggpubr::text_grob("Predicted Cognitive Abilities (Z)",size=45),
                        top = ggpubr::text_grob("Performance of Mental Health in Predicting Cognitive Abilities",size=45, face = "bold")) 

labelled_scatter_mental_health

4.3 Arrange the plots with all the other sets of features

## scatterplots with others

scatter_baseline_grid_all <-ggpubr::ggarrange(plotlist = scatter_baseline_all,
                                                        #common.legend = TRUE,
                                              ncol = 3,nrow = 1
                                              #,
                                              #          legend.grob = scatter_legend,
                                              #          legend="top"
                                              )%>%
                ggpubr::annotate_figure(top = ggpubr::text_grob("Baseline",face="bold",size=45,hjust=3.8))%>%
  ggpubr::ggarrange(legend.grob = scatter_legend,
                                                        legend="top")
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
scatter_followup_grid_all <-ggpubr::ggarrange(plotlist = scatter_followup_all,
                                                        ncol = 3,nrow = 1)%>%
                  ggpubr::annotate_figure(top = ggpubr::text_grob("Followup",face="bold",size=45,hjust=3.55))
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
scatter_all_grid <- ggpubr::ggarrange(scatter_baseline_grid_all,scatter_followup_grid_all,nrow = 2)

labelled_scatter_all <- ggpubr::annotate_figure(scatter_all_grid,
                          left= ggpubr::text_grob("Observed Cognitive Abilities (Z)",size=45,rot=90),
                        bottom = ggpubr::text_grob("Predicted Cognitive Abilities (Z)",size=45),
                        top = ggpubr::text_grob("Performance of the Brain, Genes and Social-Demographics, \nLifestyles and Developments in Predicting Cognitive Abilities",size=50, face = "bold")) 

labelled_scatter_all